package com.findme.securitydb.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * 随机数生成工具（默认13位）
 *
 * @author find me
 * @create 2020/1-21 17:13
 * @ClassName MD5Util
 **/
public class RandomUtil {
    //    public static final String ALLCHAR = "123456789";
//    public static final String LETTERCHAR = "abcdefghijkllmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
//    public static final String NUMBERCHAR = "0123456789";
//    public static final int NUMBER_LENGTH = 13;
    public static int NUMBER_RANDOM2 = 2;
    public static int NUMBER_RANDOM3 = 3;
    public static int NUMBER_RANDOM4 = 4;


    /**
     * 返回一个定长的随机字符串(只包含大小写字母、数字)
     *
     * @param length 随机字符串长度
     * @return 随机字符串
     */
//    public static String generateString(int length) {
//        StringBuffer sb = new StringBuffer();
//        Random random = new Random();
//        for (int i = 0; i < length; i++) {
//            sb.append(ALLCHAR.charAt(random.nextInt(ALLCHAR.length())));
//        }
//        return sb.toString();
//    }

    /**
     * 返回一个指定首部的的随机字符串(只包含数字)
     *
     * @param length 首字母
     * @return 随机字符串
     */
    public static String generateNumberString(int length) {
        StringBuffer sb = new StringBuffer();
        Random rand = new Random();
        SimpleDateFormat sf = new SimpleDateFormat("MMddHHmm");
        sb.append(length);
        sb.append(rand.nextInt(9) + 1);
        sb.append(sf.format(new Date()));
        sb.append(rand.nextInt(899) + 100);
        return sb.toString();
//        return null;
    }

    /**
     * 返回一个定长的随机纯字母字符串(只包含数字,第一位为3，第二位为随机数，中间八位为时间，最后三位为100到999之间的随机数)BID
     *
     * @return 随机字符串
     */
    public static String generateNumber3String() {
        StringBuffer sb = new StringBuffer();
        Random rand = new Random();
        SimpleDateFormat sf = new SimpleDateFormat("MMddHHmm");
        sb.append(NUMBER_RANDOM3);
        sb.append(rand.nextInt(9) + 1);
        sb.append(sf.format(new Date()));
        sb.append(rand.nextInt(899) + 100);
        return sb.toString();
    }

    /**
     * 返回一个定长的随机纯字母字符串(只包含数字,第一位为4，第二位为随机数，中间八位为时间，最后三位为100到999之间的随机数)PBID
     *
     * @return 随机字符串
     */
    public static String generateNumber4String() {
        StringBuffer sb = new StringBuffer();
        Random rand = new Random();
        SimpleDateFormat sf = new SimpleDateFormat("MMddHHmm");
        sb.append(NUMBER_RANDOM4);
        sb.append(rand.nextInt(9) + 1);
        sb.append(sf.format(new Date()));
        sb.append(rand.nextInt(899) + 100);
        return sb.toString();

    }

    /**
     * 返回一个定长的随机纯字母字符串(针对字典)
     *
     * @return
     */
    public static String generate2Dictionary() {
        StringBuffer sb = new StringBuffer();
        Random rand = new Random();
        SimpleDateFormat sf = new SimpleDateFormat("MMddHHmm");
        sb.append(NUMBER_RANDOM2);
        sb.append(rand.nextInt(9) + 1);
        sb.append(sf.format(new Date()));
        sb.append(rand.nextInt(899) + 100);
        return sb.toString();
    }


    /**
     * 返回一个定长的随机纯字母字符串(针对字典)
     *
     * @return
     */
    public static String generateBookId() {
        StringBuffer sb = new StringBuffer();
        Random rand = new Random();
        SimpleDateFormat sf = new SimpleDateFormat("yyMMdd");
        sb.append("ME");
        sb.append(rand.nextInt(10) + "-");
        sb.append(sf.format(new Date()) + "-");
        sb.append(rand.nextInt(899) + 100);
        return sb.toString();
    }

    /**
     * 返回一个定长的随机纯字母字符串(针对字典)
     *
     * @return
     */
//    public static List<String> generateBookId(int length) {
//        StringBuffer sb = new StringBuffer();
//        Random rand = new Random();
//        SimpleDateFormat sf = new SimpleDateFormat("yyMMdd");
//        sb.append("ME");
//        sb.append(rand.nextInt(10)+"-");
//        sb.append(sf.format(new Date())+"-");
//        sb.append(rand.nextInt(899) + 100);
//        List sbList = new LinkedList();
//        for (int i = 1; i < length; i++) {
//            Long ablong = Long.parseLong(sb.toString());
//            sbList.add(ablong);
//
//        }
//        return sb.toString();
//    }
    public static Date generateDate() {
//        SimpleDateFormat sf = new SimpleDateFormat("yyMMdd");

        return new Date();
    }


}